(function(){
    // 边栏 滚动 工具条
    var sideFixedBar = $('#sideFixedBar');
    var btnWarpper = sideFixedBar.find('.btn-warpper');
    var codeWarpper = sideFixedBar.find('.dimensional-code-warpper');
    var serviceList = new XF.CustomerServiceList({
        wrapperSelector : '.kefu-warpper',
        expandnAnimateType : 'easeOutBack',
        recoverAnimateType : 'easeInOutBack',
        interval : 130,
        changeLength : 53
    });
    //二维码显示
    (function(){

        btnWarpper.find('a.dimensional-code-btn').on('mouseover', function(){
            sideFixedBar.find( '#' + $(this).data('target-id')).show();
        }).on('mouseout', function(){
                sideFixedBar.find( '#' + $(this).data('target-id')).hide();
            });


    })();
    //返回顶端
    // 显示 客服列表
    (function(){
        var qqBtn = btnWarpper.find('.qq-online');
        var target = sideFixedBar.find('#' + qqBtn.data('target-id'));
        var expanded = false;
        qqBtn.stop(true, true).toggle(function(){
            target.stop(true, true).animate({ left: '-250px' }, 150, 'swing', function(){
                serviceList.expand(function(){
                    expanded = true;
                });
            });
        }, function(){
            if(expanded == true){
                serviceList.recoverAll(function(){
                    target.stop(true, true).animate({ left: '62px' }, 150, 'swing', function(){
                    });
                });
            }
        });
    })();

    (function(){
        var goTopBtn = btnWarpper.find('a.go-top');
        var $document = $(document);
        $(window).bind('scroll', function(){

            if($document.scrollTop() < 300 ){
                goTopBtn.hide();
            }else{
                goTopBtn.show();
            }
        }).trigger('scroll');
        
        goTopBtn.bind('click', function(){
            var $document = $(document);
            var timerID = setInterval(function(){
                if( $document.scrollTop() < 1 ){
                    clearInterval(timerID);
                }
                $document.scrollTop( $document.scrollTop() / 1.1 );
            }, 10);
        }); 
    })();
}).call(this);

